<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title> 
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            height: 100%;
        }
        button{
            width: 100px;   
            height: 30px;
            margin: 20px;
            cursor: pointer;
        }
        .mask{
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, .5);
            position: fixed;
            top: 0;
            left: 0;
            display: none;
        }
        .content{      
            width: 400px;
            height: 200px;
            background-color: #fff;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
        }
        .content span{
            width: 20px;
            height: 20px;
            background-color: #e5e5e5;
            position: absolute;
            top: 0;
            right: 0;
            line-height: 20px;
            text-align: center;
            cursor: pointer;
        }
        .content p{
            width: 100%;
            height: 100%;
            line-height: 200px;
            text-align: center;
        }
        .bg1{
            background-color: orange !important;
        }
        .bg2{
            background-color: greenyellow !important;
        }
        .bg3{
            background-color: skyblue !important;
        }
    </style>
</head>
<body>
    <button>弹窗1</button>
    <button>弹窗2</button>
    <button>弹窗3</button>
    <div class="mask">
        <div class="content">
            <span>&times;</span>
            <p>这是一个弹窗</p>
        </div>
    </div>
    <script>
        let btn=document.querySelectorAll("button")

        class Layer{
            init(bg,con){
                this.mask=document.querySelector('.mask')
                this.content=document.querySelector('.content')
                this.span=document.querySelector('span')
                this.p=document.querySelector('p')
                this.show()
                this.p.innerHTML=con
                this.content.classList.add(bg)
                this.close(bg);
            }
            show(){
                this.mask.style.display='block';
            }
            close(bg){
                this.span.onclick=()=>{
                    this.content.classList.remove(bg)
                    this.mask.style.display='none'
                }
               
            }

            static getInstance(bg,con){
                if(!this.instance){
                    this.instance=new Layer();
                }
                this.instance.init(bg,con)
                return this.instance;
            }

        }
        btn[0].onclick=function(){
            Layer.getInstance('bg1','早睡早起，身体好')
        }
        btn[1].onclick=function(){
            Layer.getInstance('bg2','你瞅啥')
        }
        btn[2].onclick=function(){
            Layer.getInstance('bg3','瞅你咋地')
        }
        console.log(Layer.instance);
        

    </script>
</body>
</html>